package com.mts.javacommon.jpabase;


import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

/**
 *
 *
 * <pre>
 *      JpaAuditorAware
 * </pre>
 *
 * @author Johnny
 * @date 2021-09-28
 */
@EnableJpaAuditing
@Configuration
@Slf4j
public class JpaAuditorAware implements AuditorAware<Long> {

    @Override
    public Optional<Long> getCurrentAuditor() {
        //String userId = SecurityUtils.getCurrentUserId();
        //TODO 获取当前用户
        Long userId = 0L;
        if (userId != null) {
            return Optional.of(userId);
        } else {
            return Optional.empty();
        }
    }

}
